<%@page import="java.util.Enumeration"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.FileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<jsp:useBean id="uploadTestBean" class="team02.server.bean.TestBean" scope="session"></jsp:useBean>
<!-- <link href="${pageContext.request.contextPath}/css/upload.css" 
	rel="stylesheet" type="text/css" />-->
<%
//権限をチェックする
if(userBean.getAccessLevel()>3){
	response.sendRedirect("404.html");
	return;
}%>

<script>
	setTitle("Make test");
	$(document).ready(function() {
		$('.uploadSubmit').click(function() {
			if(checkDuplicated()){
				$('form').submit();
			}
		});
	});
// 	$(document).ready(function() {
// 		setInterval('updateClock()', 1000);
// 		init();
// 	});
</script>
<c:set var="fileNames" value="<%=uploadTestBean.listAllTestFileName(userBean.getAlias()) %>"></c:set>
<c:forEach items="${fileNames}" var="fileName">
	<input type="hidden" class="fileName" value="${fileName}" />
</c:forEach>

<link href="${pageContext.request.contextPath}/css/org_manager.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/add_new_org.css"
	rel="stylesheet" type="text/css" />
	<link href="${pageContext.request.contextPath}/css/uploadcsv.css"
	rel="stylesheet" type="text/css" />
<c:choose>
<c:when test="${param.result != null}">
	<c:choose>
		<c:when test="${fn:startsWith(param.result, 'u=')}">
			<script>
				$(document).ready(function(){
					$(".message").html("成功！ <a href='test_page.t02?${param.result}'>テストのURL</a>");
				});
			</script>
		</c:when>
		<c:otherwise>
			<script>
				alert("<%=request.getParameter("result")%>");
			</script>
		</c:otherwise>
	</c:choose>
</c:when>
<c:otherwise>
	<%
		boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
		if (isMultiPart) {
			request.getRequestDispatcher("/UploadServlet").forward(request, response);
		}
	%>
</c:otherwise>
</c:choose>

<div class="menu1"><%@include file="/jsputils/menu.jsp"%>
	<div class="greeting_message"><%@include file="/jsputils/greeting.jsp"%></div>
</div>


	<div class="upload">
		<h1>CSV ファイルをアップロード</h1>
		<form action="uploadcsv.t02" method="post"
			enctype="multipart/form-data">
			<table border="0" cellpadding="0" cellspacing="0" class="tbl_upload">
				<tr align="center" valign="middle">
					<td valign="middle" width="16%" align="center">
						<p class="remember_me">
							<label> ファイル名 </label>
						</p>
					</td>
					<td>
						<p>
							<input type="file" name="csvfile" required="required" />
						</p>
					</td>
					<!-- 					<td width="36%" align="left"> -->
					<!-- 						<p class="submit"> -->
					<!-- 							<input type="submit" name="uploadSubmitButton" value="検索..." /> -->
					<!-- 						</p> -->
					<!-- 					</td> -->
					<td>
						<p class="button">
				<input type="button" name="uploadSubmit" class="uploadSubmit" value="サブミット"/> <input
					type="reset" name="uploadCancel" value="キャンセル" />
			</p>
					</td>
				</tr>
			</table>
			
		</form>
		<div class="upload_result">
			<h2>結果</h2>
			<p class="message">結果はこちら.</p>
		</div>
</div>